(function($){
	$.fn.setApDiv=function (date) {
		var width=150,height=100,html="",title="",button="",clickClose=true,showViewButtonIndex=0,titleHeight=0,aArray ={},thisId=$(this).attr("id")||$(this).attr("name")||$(this).attr("class")||Math.random().toString().substr(2);
		$("#"+thisId+"_mask_div").remove();
		var thisObj=$(this);
		if(date=="close"){
			if(thisObj.parent().attr("class")=="_maskShowButton"){
				thisObj.parent().parent().hide();
				$(".all_mask_div").remove();
			}else{
				thisObj.hide();
			}
		}else{
			thisObj.after("<div id='"+thisId+"_mask_div' class='all_mask_div'></div>");
			var obj=$("#"+thisId+"_mask_div");
			if(date){
				width=date.width?date.width:150;
				height=date.height?date.height:100;
				html=date.html?date.html:"";
				title=date.title?date.title:"";
				if(date.clickClose==false){
					clickClose=date.clickClose;
				}
				var buttons=date.buttons;
				if(buttons){
					button="<div id='"+thisId+"_maskShowButton' class='_maskShowButton'>";
					$.each(buttons,function(k,v){
						showViewButtonIndex++;
						button+="<a href='javascript:void(0)' id='"+thisId+"_showViewButton"+showViewButtonIndex+"'>"+k+"</a>&nbsp;";
						aArray[showViewButtonIndex]=v;
					});
					button+="</div>";
					titleHeight=20;
				}
				if(title){
					title="<div id='"+thisId+"_maskShowTitle' readonly>"+title+"<a id='"+thisId+"_closeDialog' style='position:absolute;right:10px;color:#BBBBBB;font-size:15px;'>×</a></div>";
					titleHeight+=15;
				}
			}
			if(html){
				if(html.substring(0,1)=="#"){
					html=$(html).html();
				}
			}else{
				html=thisObj.html();
			}
			
			thisObj.html(title+"<div id='"+thisId+"_maskShowView'></div>"+button);
			$("#"+thisId+"_maskShowView").html(html);
			var h=$(window).height();
			var w=$(window).width();
			var scrolltop = $(document).scrollTop();
			$("#"+thisId+"_maskShowButton").css({
				"text-align":"right",
				"padding":"13px 0",
				"font-size":"14px",
				"font-weight":"bold",
				"border-top":"1px solid #AAAAAA",
				"padding-right":"50px"
			});
			$("#"+thisId+"_maskShowButton a").css({
				"text-decoration":"none",
				"color":"#888888",
				"padding":"7px 15px",
				"border":"1px solid #FFF",
				"-moz-border-radius":"6px",
				"-webkit-border-radius":"6px",
				"border-radius":"6px"
			});
			$("#"+thisId+"_maskShowTitle").css({
				"color":"#444444",
				"text-align":"center",
				"padding":"10px 0",
				"font-size":"14px",
				"font-weight":"bold",
				"border-bottom":"1px solid #DDDDDD"
			});
			
			obj.css({
				"display":"block",
				"position":"absolute",
				"z-index":"9996",
				"background":"#000000",
				"filter":"alpha(opacity=40)",
				"-moz-opacity":"0.4",
				"opacity":"0.4",
				"width":"100%",
				"height":"100%",
				"top":scrolltop
			});
			
			thisObj.css({
				"font-weight":"bold",
				"-moz-border-radius":"6px",
				"-webkit-border-radius":"6px",
				"border-radius":"6px",
				"display": "none",
				"z-index": "9997",
				"position":"absolute",
				"background":"#fff",
				"border-left":"1px solid #CCC",
				"color":"#222",
				"font-size":"14px",
				"top":(h-height)/2-titleHeight-30+scrolltop,
				"left":(w-width)/2
			});
			$("#"+thisId+"_maskShowView").css({
				"overflow":"auto",
				"scrollbar-face-color":"#cccccc",
				"padding":"5px",
				"width":width+"px",
				"height":height+"px"
			});
			$("#"+thisId+"_closeDialog").click(function(){
				obj.remove();
				thisObj.hide();
			});
			$("#"+thisId+"_maskShowButton a").mouseover(function(){
				$(this).css({"border-color":"#CCCCCC","background":"#EEEEEE","color":"#333333"});
			}).mouseout(function(){
				$(this).css({"border-color":"#FFFFFF","background":"#FFFFFF","color":"#888888"});
			});
			thisObj.slideDown(500);
			obj.click(function(){
				if(clickClose){
					obj.remove();
					thisObj.hide();
				}
			});
			$(document).scroll(function(){
				var thisTo=$(document).scrollTop();
				thisObj.css({
					"top":(h-height)/2-titleHeight-30+thisTo
				});
				obj.css({"top":thisTo});
			});
			for(var i=showViewButtonIndex;i>0;i--){
				$("#"+thisId+"_showViewButton"+i).click(aArray[i]);
			}
			$("#"+thisId+"_maskShowTitle").mousedown(function (event) {
				var isMove = true;
				var abs_x = event.pageX - thisObj.offset().left;
				var abs_y = event.pageY - thisObj.offset().top;
				$("#"+thisId+"_maskShowTitle").css({"cursor":"move"});
				$(document).mousemove(function (event) {
					if (isMove) {
						var moveLeft=event.pageX - abs_x;
						var moveTop=event.pageY - abs_y;
						thisObj.css({'left':moveLeft, 'top':moveTop});
					}
				}).mouseup(function () {
					$("#"+thisId+"_maskShowTitle").css({"cursor":"default"});
					isMove = false;
				});
			});
		}
	}
	$.fn.imgDialog=function (_169) {
		var obj=$(this);
		var thisId=obj.attr("id")?obj.attr("id"):Math.random().toString().substr(2);
		var thisSrc=obj.attr("src");
		var h=$(window).height();
		var w=$(window).width();
		$("#"+thisId+"_mask_div").remove();
		$("#"+thisId+"_show_img_div").remove();
		obj.after("<div id='"+thisId+"_mask_div' style='display:none;width:100%;height:100%;'></div>");
		obj.after("<div id='"+thisId+"_show_img_div' style='display:none;'><img src='"+thisSrc+"' style='max-height:"+(h-40)+"px;max-width:"+(w-200)+"px'/></div>");
		
		var maskObj=$("#"+thisId+"_mask_div");
		var imgObj=$("#"+thisId+"_show_img_div");
		var scrollTop=$(document).scrollTop();
		
		var height=imgObj.height();
		var width=imgObj.width();
		maskObj.css({
			"display":"block",
			"position":"absolute",
			"z-index":"9998",
			"background":"#000000",
			"filter":"alpha(opacity=40)",
			"-moz-opacity":"0.4",
			"opacity":"0.4",
			"top":scrollTop
		});
		imgObj.css({
			"display":"block",
			"z-index": "9999",
			"position":"absolute",
			"background":"#fff",
			"border-left":"1px solid #CCC",
			"top":(h-height)/2+scrollTop,
			"left":(w-width)/2
		});
		$(document).scroll(function(){
			var thisTop=$(document).scrollTop();
			imgObj.css({
				"top":(h-height)/2+thisTop
			});
			maskObj.css({"top":thisTop});
		});

		maskObj.click(function(){
			maskObj.remove();
			imgObj.remove();
		});
		if(_169){
			imgObj.click(function(){
				maskObj.remove();
				imgObj.remove();
			});
		}
	}
})(jQuery);